package com.android.demos.module.main.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aaron.android.framework.base.widget.recycleview.BaseRecycleViewAdapter;
import com.aaron.android.framework.base.widget.recycleview.BaseRecycleViewHolder;
import com.aaron.android.framework.base.widget.recycleview.ItemTouchHelperAdapter;
import com.aaron.android.framework.base.widget.recycleview.ItemTouchHelperViewHolder;
import com.android.demos.R;
import com.soybean.framework.common.LogUtils;

/**
 * Created on 16/4/8.
 *
 * @author aaron.huang
 * @version 1.0.0
 */
public class MainRecyclerAdapter extends BaseRecycleViewAdapter<MainRecyclerAdapter.MainRecyclerViewHolder, String> implements ItemTouchHelperAdapter{

    private static final String TAG = "MainRecyclerAdapter";

    public MainRecyclerAdapter(Context context) {
        super(context);
    }

    @Override
    protected MainRecyclerViewHolder createViewHolder(ViewGroup parent) {
        View itemView = LayoutInflater.from(getContext()).inflate(R.layout.main_recycler_item, parent, false);
        return new MainRecyclerViewHolder(itemView);
    }

    class MainRecyclerViewHolder extends BaseRecycleViewHolder<String> implements ItemTouchHelperViewHolder{

        private TextView mTitleTextView;

        public MainRecyclerViewHolder(View itemView) {
            super(itemView);
            mTitleTextView = (TextView) itemView.findViewById(R.id.text_view_main_item);
        }

        @Override
        public void bindViews(String object) {
            mTitleTextView.setText(object);
        }

        @Override
        public void onItemSelected() {

        }

        @Override
        public void onItemClear() {

        }
    }

    @Override
    public boolean onItemMove(int fromPosition, int toPosition) {
        notifyItemMoved(fromPosition, toPosition);
        return true;
    }

    @Override
    public void onItemDismiss(int position) {
        notifyItemRemoved(position);
    }

    @Override
    public void onItemMoveFinish() {
        LogUtils.d(TAG, "onItemMoveFinish----");
    }
}
